﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pseudogenerator.Common.Generators.Core;

namespace Pseudogenerator.Common.Generators
{
    public class Green
        : MethodBase
    {
        public uint k { get; set; }
        public uint vn { get; private set; }
        public uint vnk { get; private set; }
        

        public override bool CanGenerateNext
        {
            get { return k>5 && ActualIndex<=m && m>k; }
        }

        public override uint GetNextValue()
        {
            var r = (vn + vnk) % m;
            return r;
        }

        public override List<RandomNumber> GetFullList()
        {
            var r = new List<RandomNumber>();
            Fibonacci fb = new Fibonacci();
            fb.m=this.m;
            fb.x_1=0;
            fb.x0=1;
            var Fibonacci = fb.GetFullList();
            while (CanGenerateNext)
            {
                vn = (uint) (Fibonacci[Fibonacci.Count() - (int) k].Uniform * m);
                vnk = (uint) (Fibonacci[(int) ActualIndex].Uniform * m);
                var v = GetNextValue();


                var tmp = new RandomNumber(this.m) { n = ActualIndex, Xn = v };
                r.Add(tmp);
                Fibonacci.Add(tmp);
                ActualIndex++;

            }
            ActualIndex = 0;
            return r;
        }

        public override string ToString()
        {
            return string.Format("k = {0}, m = {1}", k, m);
        }
    }

    
}
